<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
  </head>
  <body>
    <button id="get">GET</button>
    <button id="post">POST</button>
    <button id="delete">DELETE</button>
    <button id="jsonp">JSONP</button>
  </body>

  <script>
    $('#get').on('click', () => {
      $.ajax({
        type: 'GET',
        url: 'http://127.0.0.1:4399/api/get',
        data: {
          name: '张三',
          age: 18,
          gender: '男',
        },
      })
    })

    $('#post').on('click', () => {
      $.ajax({
        type: 'POST',
        url: 'http://127.0.0.1:4399/api/post',
        data: {
          bookname: '西游记',
          author: '吴承恩',
        },
      })
    })

    $('#delete').on('click', () => {
      $.ajax({
        type: 'DELETE',
        url: 'http://127.0.0.1:4399/api/delete',
      })
    })

    $('#jsonp').on('click', () => {
      $.ajax({
        method: 'GET',
        url: 'http://127.0.0.1:4399/api/jsonp',
        dataType: 'jsonp',
        success: (res) => {
          console.log(res)
        },
      })
    })
  </script>
</html>
